package com.github.bitsapling.sapling.service.impl;

import com.github.bitsapling.sapling.entity.imagePath;
import com.github.bitsapling.sapling.mapper.imagePathMapper;
import com.github.bitsapling.sapling.service.imgPathService;
import jakarta.annotation.Resource;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;

@Service
public class imgPathServiceImpl implements imgPathService {
    @Resource
    private imagePathMapper imgPathMapper;

    @Override
    public imagePath getImagePath(Long id) {
        return imgPathMapper.selectById(id);
    }

    @Override
    public imagePath createOrUpdate(@NotNull imagePath imgPath) {
        if (imgPath.getId() != null) {
            return imgPathMapper.updateById(imgPath) == 1 ? imgPath : null;
        }
        return imgPathMapper.insert(imgPath) > 0 ? imgPath : null;
    }

    @Override
    public imagePath findImagePathByname(String name) {
        return imgPathMapper.selectByName(name);
    }
}
